package person.learn.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * web socket 配置
 * Created by barton on 16-5-19.
 */
@Configuration
@EnableWebSocketMessageBroker// 开启使用STOMOP协议来传输基于代理的消息
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
    /**
     * 消息代理
     *
     * @param registry
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 广播式应配置一个/topic消息代理
        registry.enableSimpleBroker("/topic", "/queue");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
        // 使用SockJS协议,设置一个可以进行链接的端点,并指定映射的URL
        stompEndpointRegistry.addEndpoint("/endpointBarton").withSockJS();
        stompEndpointRegistry.addEndpoint("/endpointChat").withSockJS();

    }
}
